{extend name="public/nav" /}
{block name="title"} 档案管理系统 {/block}

{block name="content"}
<style>
    html,body{
        height: 100%;
    }
    input{
        border: none;
    }
    .layui-input-block{
        margin-left: 0px;
    }
    .layui-form-select dl dd.layui-this {
        background-color: #1296db;
        color: #fff;
    }
    #img img{
        width: 120px;
        height: 120px;
        border-radius: 250px;
    }
    .layui-btn-color{
        background-color: transparent;
        color: #2D93CA;
        font-weight: bold;
        display: block;
        width: 100%;
        border: 1px solid #1296db;
    }
    .upload-img{
        width: 30.5%;
        padding: 1%;
        border: 1px solid #ccc;
        text-align: center;
        float: left;
    }
    .upload-img img{
        height: 60px;
        margin-bottom: 5px;
    }
</style>
<div class="site-content" style="background-color: #cccccc;">
    <div class="site-h1">
        <i class="layui-icon layui-icon-left" onclick="window.history.back(-1)"></i>档案编辑
    </div>
    <div class="layui-container">
        <div class="site-text" style="margin-top: 20px;">
            <form class="layui-form" method="post">
                <input type="hidden" name="id" value="{$field.id}">
                <div class="layui-form-item">
                    <div>档案名称</div>
                    <div class="layui-input-block">
                        <input type="text" name="name" value="{$field.name}" required lay-verify="required"
                            placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>分公司</div>
                    <div class="layui-input-block">
                        <select name="enter_id">
                            {foreach $branch as $p}
                            <option value="{$p.id}" {if condition="$p.id == $field.enter_id" } selected {/if}>{$p.branch_name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>管道段</div>
                    <div class="layui-input-block">
                        <select name="pipe_id">
                            {foreach $pipes as $p}
                            <option value="{$p.unit_id}" {if condition="$p.unit_id == $field.pipe_id" } selected {/if}>{$p.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>上传图片</div>
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-color" id="pic_btn">
                            <i class="layui-icon">&#xe67c;</i>
                        </button>
                    </div>
                    {if condition="!empty($field['pic'])"}
                    <div id="pics" style="display: block;">
                        {foreach $field['pic'] as $p}
                        <div class="upload-img">
                            <input type="hidden" value="{$p}" name="pic[]">
                            <img src="{$p}" />
                            <button type="button" class="layui-btn layui-btn-xs" onclick="del(this)" data-url="{$p}">删除</button>
                        </div>
                        {/foreach}
                    </div>
                    {else}
                    <div id="pics" style="display: none;"></div>
                    {/if}
                </div>
                <div class="layui-form-item">
                    <div>焊口编号</div>
                    <div class="layui-input-block">
                        <input type="text" name="order_id" value="{$field.order_id}" required lay-verify="required"
                            placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>桩号编号</div>
                    <div class="layui-input-block">
                        <input type="text" name="pile_number" value="{$field.pile_number}" required
                            lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>施工日期</div>
                    <div class="layui-input-block">
                        <input type="text" name="const_time" value="{:date('Y-m-d',$field.const_time)}" id="const_time"
                            required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>检测日期</div>
                    <div class="layui-input-block">
                        <input type="text" name="test_time" value="{:date('Y-m-d',$field.test_time)}" id="test_time"
                            required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>施工单位</div>
                    <div class="layui-input-block">
                        <input type="text" name="const_unit" value="{$field.const_unit}" required lay-verify="required"
                            placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>机组</div>
                    <div class="layui-input-block">
                        <input type="text" name="crew" value="{$field.crew}" required lay-verify="required"
                            placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>焊材厂家</div>
                    <div class="layui-input-block">
                        <input type="text" name="manufactor" value="{$field.manufactor}" required lay-verify="required"
                            placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>无损检测单位</div>
                    <div class="layui-input-block">
                        <input type="text" name="ndt_unit" value="{$field.ndt_unit}" required lay-verify="required"
                            placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>监理单位</div>
                    <div class="layui-input-block">
                        <input type="text" name="supervisor_unit" value="{$field.supervisor_unit}" required
                            lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>内检测里程</div>
                    <div class="layui-input-block">
                        <input type="text" name="mileage" value="{$field.mileage}" required lay-verify="required"
                            placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>内检测编号</div>
                    <div class="layui-input-block">
                        <input type="number" name="mileage_number" value="{$field.mileage_number}" required
                            lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>排查结果</div>
                    <div class="layui-input-block">
                        <input type="text" name="Invest_res" value="{$field.Invest_res}" required lay-verify="required"
                            placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-color" lay-submit lay-filter="add">保存</button>
                    </div>
                </div>
            </form>

            <script type="text/javascript">
                layui.use(['form', 'upload', 'jquery', 'laydate'], function () {
                    var form = layui.form,
                        upload = layui.upload,
                        layer = layui.layer,
                        $ = layui.jquery,
                        laydate = layui.laydate;
                    //上传
                    upload.render({
                        elem: '#pic_btn' //绑定元素
                        , url: '{:url("index/api/upload")}' //上传接口
                        , done: function (res) {
                            //上传完毕回调
                            if (res.code == 0) {
                                layer.msg('上传成功')
                                var imgHtml = '<div class="upload-img">' +
                                    '<input type="hidden" value="' + res.data.path + '" name="pic[]">' +
                                    '<img src="' + res.data.path + '" />' +
                                    '<button type="button" class="layui-btn layui-btn-xs" onclick="del(this)" data-url="' + res.data.path + '">删除</button>'
                                    + '</div>';
                                $('#pics').append(imgHtml).show();
                            } else {
                                layer.msg('上传失败')
                            }
                        }
                        , error: function () {
                            layer.msg('上传失败');
                        }
                    });
                    //日期初始化
                    laydate.render({
                        elem: '#const_time',
                    })

                    laydate.render({
                        elem: '#test_time',
                    })
                    //提交
                    form.on('submit(add)', function (data) {
                        $.post('{:url("index/archives/edit")}', data.field, function (res) {
                            if (res.code == 0) {
                                layer.msg('保存成功', { icon: 6, time: 1000 }, function () {
                                    window.location.href = '{:url("index/archives/index")}';
                                })
                            } else {
                                layer.msg('保存失败');
                            }
                        }, 'json');
                        return false;
                    });
                })

                function del(obj) {
                    layui.use(['jquery'], function () {
                        var $ = layui.jquery;
                        //删除图片
                        $(obj).parent().remove();
                    })
                }
            </script>
        </div>
    </div>
</div>
{/block}